package com.base.api.cdr;

import com.base.api.pms.PmsPublicSqlQuery;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import java.text.MessageFormat;
import java.util.Map;

/**
 * @author wnhuang
 * @Package com.base.api.cdr
 * @date 2020-12-19 19:19
 */
@Component
public class DepartmentInfo extends PmsPublicSqlQuery {

    @Override
    public String splicSql(String sql, Map<String, Object> param){
        StringBuilder param1 = new StringBuilder();
        if(param != null){
            if(param.get("HospitalNo") != null && !StringUtils.isBlank((String) (param.get("HospitalNo")))){
                param1.append(" and PROPERTY1 = '" + param.get("HospitalNo") + "'");
            }
            if (param.get("KeyWord") != null && !StringUtils.isBlank((String) (param.get("KeyWord")))) {
                param1.append(MessageFormat.format(" AND (\n" +
                        "         upper(PINYIN_CODE) LIKE concat(\"%\",upper(\"{0}\"),\"%\")\n" +
                        "         or upper(WUBI_CODE) LIKE concat(\"%\",upper(\"{0}\"),\"%\")\n" +
                        "         or upper(CODE) LIKE concat(\"%\",upper(\"{0}\"),\"%\")\n" +
                        "        or upper(NAME) LIKE concat(\"%\",upper(\"{0}\"),\"%\" ))", param.get("KeyWord")));

            }
        }
        return MessageFormat.format(sql, param1.toString());
    };
}
